package Edchl7;

import com.orion.symphonia3.MessageElement;
import com.orion.symphonia3.MessageComponent;
import com.orion.symphonia3.BadParameterException;

public class EDC_HL7MsgSetDefault extends MessageComponent {
	
	//Constructor
	public EDC_HL7MsgSetDefault(MessageElement elem) {
		super(elem);
	}

	//Methods
	public MessageComponent append(String messageName) {

		if(messageName.equals("ACK"))
			return new EDC_HL7MsgACK(elem.appendElement(messageName));
		else if (messageName.equals("ORFR04"))
			return new EDC_HL7MsgORFR04(elem.appendElement(messageName));
		else if (messageName.equals("ORFW02"))
			return new EDC_HL7MsgORFW02(elem.appendElement(messageName));
		else if (messageName.equals("QCKQ02"))
			return new EDC_HL7MsgQCKQ02(elem.appendElement(messageName));
		else if (messageName.equals("QRYR02"))
			return new EDC_HL7MsgQRYR02(elem.appendElement(messageName));

		else
			return null;	//Message type does not exists
	}

	public MessageComponent item(int index) throws BadParameterException {
		if (index >= getCount())
			throw new BadParameterException("Index is out of bounds");
		MessageElement item = elem.getElementAt(index);
		String name = item.getName();

		if (name.equals("ACK"))
			return new EDC_HL7MsgACK(item);
		else if (name.equals("ORFR04"))
			return new EDC_HL7MsgORFR04(item);
		else if (name.equals("ORFW02"))
			return new EDC_HL7MsgORFW02(item);
		else if (name.equals("QCKQ02"))
			return new EDC_HL7MsgQCKQ02(item);
		else if (name.equals("QRYR02"))
			return new EDC_HL7MsgQRYR02(item);

		else
			return null;	//Message type does not exists
	}

	public int getCount() {
		return elem.getElementCount();
	}
}

